﻿using System;
using SharpSqlAnalyzer.pp.utils;

namespace SharpSqlAnalyzer.pp.stmtformatter.type.comm
{
	// Token: 0x02000200 RID: 512
	public class CompactModeStmtFormatter : AbstractStmtFormatter
	{
		// Token: 0x060011FB RID: 4603 RVA: 0x003176BD File Offset: 0x003158BD
		public new virtual void format(TCustomSqlStatement stmt)
		{
			this.runProcessor<TCustomSqlStatement>(this.SpecialProcessors, stmt);
			this.compact(stmt);
		}

		// Token: 0x060011FC RID: 4604 RVA: 0x003176D4 File Offset: 0x003158D4
		private void compact(TCustomSqlStatement stmt)
		{
			if (stmt == null)
			{
				return;
			}
			TSourceToken startToken = stmt.startToken;
			TSourceToken endToken = stmt.endToken;
			if (startToken == null || endToken == null)
			{
				return;
			}
			int lineWidth = this.Option.lineWidth;
			int num = 0;
			for (int i = startToken.posinlist; i <= endToken.posinlist; i++)
			{
				TSourceToken tsourceToken = startToken.container.get(i);
				SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createNoFormatFlagToken());
				if (tsourceToken.astext != null)
				{
					if (tsourceToken.tokentype == ETokenType.ttsimplecomment)
					{
						tsourceToken.astext = "/* " + tsourceToken.astext + "*/";
					}
					if (tsourceToken.astext.Length >= lineWidth)
					{
						tsourceToken.astext = "\n" + tsourceToken.astext + "\n";
						num = 0;
					}
					else
					{
						num += tsourceToken.astext.Length;
						if (num > lineWidth)
						{
							tsourceToken.astext = "\n" + tsourceToken.astext;
							num = tsourceToken.astext.Length;
						}
					}
				}
			}
		}
	}
}
